# delimit;
set more off;

* original format was SPSS, I saved to Stata .dta format for use.;
* if using Stata 16, can use import spss to load survey data.;
use Mid-Nov01.dta, clear;

recode q1 	(1=1 "Approve")
		(2=0 "Disapprove")
		(9=.), gen(approve);

recode q44a (5/9=.)(1=4)(2=3)(3=2)(4=1), gen(opfed);
recode q44b (5/9=.)(1=4)(2=3)(3=2)(4=1), gen(opst);
recode q44c (5/9=.)(1=4)(2=3)(3=2)(4=1), gen(oploc);
	
	
label define opinions_rev

	4 "Very favorable"   
	3 "Mostly favorable"      
	2 "Mostly unfavorable"      
	1 "Very unfavorable"  ;
 
foreach var in fed st loc {;
	label values op`var' opinions_rev;
	};

recode q41 
  (1=6  "More than once a week")
  (2=5  "Once a week")
  (3=4  "Once or twice a month")
  (4=3  "A few times a year")
  (5=2  "Seldom")
  (6=1  "Never"), gen(r_attend);

recode q46 (1=1 "Born again")(2=0 "Not born again")(9=.), gen(r_bornagn);

recode sex (1=1 "Male")(2=0 "Female"), gen(r_male);
recode age (98 99=.), gen(r_age);
recode educ (8 9=.), gen(r_educ);
recode hisp (1=1)(2=0)(9=.), gen(r_hisp);
recode race (1=1)(2/4=0)(9=.), gen(r_white);
   replace r_white=0 if r_hisp==1;
recode race (2=1)(1=0)(3/4=0)(9=.), gen(r_black);
   replace r_black=0 if r_hisp==1;
recode race (3=1)(1 2=0)(4=0)(9=.), gen(r_asian);
   replace r_asian=0 if r_hisp==1;   

rename d7 marital;

recode marital 	(1=1 "Married")
				(2 3=2 "Divorced")
				(3=3 "Widowed")
				(4=4 "Single")(9=.), gen(r_marital);
tab marital, gen(r_marital);

recode q38 (1=1)(2=0)(9=.), gen(r_parent);

recode d8 (9=.), gen(r_income);
label define inc

           1 "Less than $10,000"
           2 "$10,000 to under $20,000"
           3 "$20,000 to under $30,000"
		   4 "$30,000 to under $40,000"
           5 "$40,000 to under $50,000"
           6 "$50,000 to under $75,000"
           7 "$75,000 to under $100,000"
           8 "$100,000 or more" ;
label values r_income inc;
		   
recode d9
           (1=1 "Yes, registered")
           (2=0 "No, not registered")
           (9=. ), gen(r_regist);  
rename d10 party;
rename d10a partyln;
recode party (1=1)(2/5=0)(9=.), gen(gop);
recode party (1=0)(2=1)(3/5=0)(9=.), gen(dem);
recode party (1/2=0)(3/5=1)(9=.), gen(ind);

recode party (1=1 "Republican")(2=5 "Democrat") (3/5=3 "Independent")(9=.), gen(partyid);
replace partyid=2 if partyid==3 & partyln==1;
replace partyid=3 if partyid==3 & partyln==9;
replace partyid=4 if partyid==3 & partyln==2;		   
		   
recode d12 (9=.), gen(ideo_all) label(D12);
tab ideo_all, gen(ideo);

recode d13 (1=1 "Own")(2 3=0 "Rent")(9=.), gen(r_ownhome);
recode d14 (9=.), gen(employ);
tab employ, gen(employ);

recode d16 (1/3=1)(4=0)(9=.), gen(r_union);

tostring fips, replace;
gen new=substr(fips, -3, 3);
destring fips, replace;
destring new, replace;
replace fips=(fips-new)/1000;
drop new;
gen year=2001;


keep fips r_* op* approve gop dem ind partyid ideo* employ* year weight;

codebook r_* op* approve gop dem ind partyid ideo* employ*;
